package com.example.concurrent.demo.runnable;

import java.util.Date;

/**
 * @author susc
 * @title: MyRunnable
 * @projectName concurrent-demo
 * @description: 这是一个简单的Runable类，需要大约5秒钟来执行其任务
 * @date 2021/9/2810:15
 */
public class MyRunnable implements Runnable{

    private String command;

    public MyRunnable(String command) {
        this.command = command;
    }

    @Override
    public void run() {
        String threadStartInfo = Thread.currentThread().getName() + " Start. Time = " + new Date();
        String threadEndInfo = Thread.currentThread().getName() + " End. Time = " + new Date();
        System.out.println(threadStartInfo);
        processCommand();
        System.out.println(threadEndInfo);
    }

    private void processCommand() {
        try {
            Thread.sleep(5000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        return this.command;
    }
}
